import { Component, Injectable, Input, Output, EventEmitter } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { NzMessageService } from 'ng-zorro-antd';
import { ControlApiService } from '@core/controlApi.service';

@Injectable({ providedIn: 'root' })

@Component({
    selector: 'app-controlczjy',
    templateUrl: './czjy.component.html',
    styles: [`
        .m020{margin: 0 20px;}
        .m100{margin:10px 0;}
        .mc{margin:20px;text-align:center}
    `]
})

export class ControlczjyComponent {
    @Input() czjyAlarmType: any;
    @Input() nid: any;

    wzjyData: any = [{ id: '' }];
    wtkTitle = '';
    wtkVisible = false;
    czjyVisible = false;
    wtkIframe: any;
    dropDownList = [{
        id: 'hkgst',
        text: '沪昆高速台'
    }, {
        id: 'nkkzt',
        text: '南昆客专台'
    }, {
        id: 'nkhgpst',
        text: '南昆、红果普速台'
    }, {
        id: 'hkpst',
        text: '沪昆普速台'
    }];

    @Output()
    private btnClick = new EventEmitter();

    constructor(
        private sanitizer: DomSanitizer,
        private message: NzMessageService,
        private controlApiService: ControlApiService
    ) { }

    addData() {
        this.wzjyData.push({ 'id': '' });
    }
    saveData(type, name) {
        this.wtkTitle = name;
        this.btnClick.emit({ type, param: name });
        switch (type) {
            case '1':
                
                break;
            case '2':
                this.wtkVisible = true;
                this.wtkIframe = this.sanitizer.bypassSecurityTrustHtml('<iframe src="/csmis/prod/daywork/waDayWorkInputnew.jsp" frameborder="0" style="width:100%;height:500px;position:absolute;z-index:9"></iframe>');
                window.addEventListener('message', () => {
                    this.wtkVisible = false;
                }, false);
                break;
            case '3':
                let data = '';
                for (const item of this.wzjyData) {
                    if (item.id !== '') {
                        data += ',' + item.id;
                    }
                }
                if (!this.nid) {
                    this.message.create('error', '没有报警的设备无法填写处置意见');
                    return;
                }
                if (data === '') {
                    this.message.create('error', '请填写内容后再保存');
                    return;
                }
        }
        if (!this.czjyAlarmType) {
            this.message.create('error', '请选择报警类型');
            return;
        }
    }
    czjyOpen() {
        this.czjyVisible = true;
    }
    czjylOk() {
        this.czjyVisible = false;
    }
    wtkOk() {
        this.wtkVisible = false;
    }
}
